package com.example.hehecat.yuejian1.mvp.model;

import com.example.hehecat.yuejian1.http.RetrofitHttp;
import com.example.hehecat.yuejian1.mvp.contract.GameInfoContract;
import com.example.hehecat.yuejian1.mvp.model.bean.GameBean;
import com.example.hehecat.yuejian1.mvp.model.bean.SuccessBean;

import okhttp3.OkHttpClient;
import retrofit2.Callback;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class GameInfoModel implements GameInfoContract.Model {
    @Override
    public void getGame(int game_id, Subscriber<GameBean> subscriber) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        RetrofitHttp.getRetrofit(builder).getGameInfo(game_id)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    @Override
    public void gameEnroll(int user_id, int game_id, Callback<SuccessBean> callback) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        RetrofitHttp.getRetrofit(builder).gameEnroll(user_id, game_id)
                .enqueue(callback);
    }

    @Override
    public void collectGame(int user_id, int game_id, Callback<SuccessBean> callback) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        RetrofitHttp.getRetrofit(builder).collectGame(user_id, game_id)
                .enqueue(callback);
    }

    @Override
    public void isGameCollect(int user_id, int game_id, Callback<SuccessBean> callback) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        RetrofitHttp.getRetrofit(builder).isGameCollect(user_id, game_id)
                .enqueue(callback);
    }
}
